package com.emmy.walnut.app;

import android.app.Application;

import com.emmy.walnut.constant.AppConstant;
import com.emmy.walnut.model.Label;
import com.emmy.walnut.model.User;
import com.emmy.walnut.util.MD5Util;
import com.emmy.walnut.util.PreferenceUtil;

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        init();
    }

    private void init(){
        AppConstant.APPLICATION_CONTEXT = this;
        if (!PreferenceUtil.getBoolean("firstLogin")){
            PreferenceUtil.putBooleanWithApply("firstLogin", true);
            new Thread(new Runnable() {
                @Override
                public void run() {
                    AppDatabase.getInstance().labelDao().insert(new Label("睡眠",false,null));
                    AppDatabase.getInstance().labelDao().insert(new Label("运动",false,null));
                    AppDatabase.getInstance().labelDao().insert(new Label("阅读",false,null));
                    AppDatabase.getInstance().labelDao().insert(new Label("工作",false,null));
                    AppDatabase.getInstance().labelDao().insert(new Label("学习",false,null));
                    AppDatabase.getInstance().labelDao().insert(new Label("娱乐",false,null));
                    AppDatabase.getInstance().userDao().insert(new User("12345678", MD5Util.md5("12345678")));
                }
            }).start();
        }
    }
}
